package com.station.administrators.controller;

import com.open.capacity.common.web.Result;
import com.open.capacity.common.model.JournalismClassModel;
import com.station.administrators.service.JournalismClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YangGang
 * @Title: 新闻分类管理
 * @Description: TODO
 * @date 2021/6/29/10:45
 */
@RestController
@RequestMapping("/journalismClass")
public class JournalismClassController {
    @Autowired
    private JournalismClassService journalismClassService;

    @PostMapping("/add")
    public Object add(JournalismClassModel journalismClass){
        journalismClassService.add(journalismClass);
        return Result.succeed("添加成功！");
    }
    @PostMapping("/update")
    public Object update(JournalismClassModel journalismClass){
        journalismClassService.update(journalismClass);
        return Result.succeed("修改成功！");
    }
    @PostMapping("/delete")
    public Object delete(Long id){
        journalismClassService.delete(id);
        return Result.succeed("添加成功！");
    }
    @GetMapping("/findById")
    public Object findById(Long id){
        JournalismClassModel journalismClass=journalismClassService.findById(id);
        return Result.succeed(journalismClass,"添加成功！");
    }
    @GetMapping("/findAll")
    public Object findAll(JournalismClassModel journalismClass){
        List<JournalismClassModel> journalismClassList =journalismClassService.findAll(journalismClass);
        Integer count=journalismClassService.getCount(journalismClass);
        Map<String,Object> map=new HashMap<>();
        map.put("journalismClassList",journalismClassList);
        map.put("count",count);
        return Result.succeed(map,"添加成功！");
    }

}
